package org.neframework.webtest.action.xyk.customer;

import java.util.List;
import java.util.Map;

import org.neframework.webtest.base.BaseController;
import org.neframework.webtest.model.t_s_customer;
import org.neframework.webtest.service.CustomerService;

import com.tmsps.neframework.core.utils.JsonTools;
import com.tmsps.neframework.mvc.annotation.Controller;
import com.tmsps.neframework.mvc.annotation.RequestMapping;
import com.tmsps.neframework.mvc.annotation.ResponseBody;
import com.tmsps.neframework.mvc.plugin.Tip;

@Controller
@RequestMapping("/cp/xyk/customer")
public class CustomerController extends BaseController {

	private static final CustomerService custService = new CustomerService();

	@RequestMapping("/list")
	public String list() {
		return "/jsp/xyk/customer/list.jsp";
	}

	@RequestMapping("/list_data")
	@ResponseBody
	public void list_data(String srh_name, String srh_bank_id) {
		
		List<Map<String, Object>> list = custService.selectCustomerList(
				srh_name, srh_bank_id, sort_params, page);

		result.put("list", list);
	}

	@RequestMapping("/add")
	@ResponseBody
	public void add(t_s_customer cust) {
		oc.saveObj(cust);

		this.setTipMsg(true, "保存成功!", Tip.Type.success);
	}

	@RequestMapping("/edit_form")
	@ResponseBody
	public String edit_form(String kid) {
		t_s_customer cust = (t_s_customer) oc.findObjById(kid,
				t_s_customer.class);

		Map<String, Object> map1 = JsonTools.objToMap("cust", cust);

		return JsonTools.toJson(map1);
	}

	@RequestMapping("/edit")
	@ResponseBody
	public void edit(t_s_customer cust) {
		t_s_customer custDb = (t_s_customer) oc.findObjById(cust.getKid(),
				t_s_customer.class);
		custDb.setName(cust.getName());
		custDb.setSex(cust.getSex());
		custDb.setMobile(cust.getMobile());
		custDb.setAddress(cust.getAddress());
		custDb.setTelephone(cust.getTelephone());
		custDb.setAnimal(cust.getAnimal());
		custDb.setEducation(cust.getEducation());
		custDb.setAge(cust.getAge());
		custDb.setErcode(cust.getErcode());
		custDb.setErcode_addr(cust.getErcode_addr());
		custDb.setAddress_old(cust.getAddress_old());
		custDb.setEmail(cust.getEmail());
		custDb.setQs_name(cust.getQs_name());
		custDb.setQs_mobile(cust.getQs_mobile());
		custDb.setQs_relation(cust.getQs_relation());
		custDb.setQs_other_name(cust.getQs_other_name());
		custDb.setQs_other_mobile(cust.getQs_other_mobile());
		custDb.setQs_other_relation(cust.getQs_other_relation());
		custDb.setCompany(cust.getCompany());
		custDb.setCompany_address(cust.getCompany_address());
		custDb.setCompany_depart(cust.getCompany_depart());
		custDb.setCompany_position(cust.getCompany_position());
		custDb.setCompany_telephone(cust.getCompany_telephone());
		oc.updateObj(custDb);

		this.setTipMsg(true, "保存成功!", Tip.Type.success);
	}

	@RequestMapping("/del")
	@ResponseBody
	public void del(String kid) {
		oc.delObjById(kid, t_s_customer.class);

		this.setTipMsg(true, "删除成功!", Tip.Type.success);
	}

}
